﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using SlimDX;
using DarkLight.Model;

namespace DarkLight.Model
{
    public static class ConvoyManager
    {
        private static List<Convoy> _convoys = new List<Convoy>();

        public static void RegisterConvoy(Convoy convoy)
        {
            _convoys.Add(convoy);
        }

        public static void UnregisterConvoy(Convoy convoy)
        {
            _convoys.Remove(convoy);
            convoy = null;
        }

        public static List<Convoy> GetConvoys()
        {
            return _convoys;
        }

        public static List<Convoy> GetElementConvoys(IPosition element)
        {
            var convoys = _convoys.Where(c => c.Destination == element || c.Origin == element).ToList();
            if (element is IEnvironment)
            { 
                var eelement = element as IEnvironment;
                foreach (var item in eelement.Environment)
                {
                    convoys.AddRange(_convoys.Where(c => c.Destination == item));
                }
            }
            return convoys;
        }
    }
}
